/*************************************************************************
 *                     COPYRIGHT NOTICE
 *            Copyright 2024 Horizon Robotics, Inc.
 *                   All rights reserved.
 *************************************************************************/
#include <string>
#include <fstream>
#include <sstream>
#include <iostream>
#include "gles_debug.hpp"

void eglCheckError_(const char *file, int line)
{
	EGLint errorCode;
	while ((errorCode = eglGetError()) != EGL_SUCCESS)
	{
		std::string error;
		switch (errorCode)
		{
			case EGL_NOT_INITIALIZED:                  	error = "EGL_NOT_INITIALIZED"; break;
			case EGL_BAD_ACCESS:                  		error = "EGL_BAD_ACCESS"; break;
			case EGL_BAD_ALLOC:                		error = "EGL_BAD_ALLOC"; break;
			case EGL_BAD_ATTRIBUTE:             		error = "EGL_BAD_ATTRIBUTE"; break;
			case EGL_BAD_CONTEXT:                		error = "EGL_BAD_CONTEXT"; break;
			case EGL_BAD_CONFIG:               		error = "EGL_BAD_CONFIG"; break;
			case EGL_BAD_CURRENT_SURFACE:         		error = "EGL_BAD_CURRENT_SURFACE"; break;
			case EGL_BAD_DISPLAY: 				error = "EGL_BAD_DISPLAY"; break;
			case EGL_BAD_SURFACE:                  		error = "EGL_BAD_SURFACE"; break;
			case EGL_BAD_MATCH:                  		error = "EGL_BAD_MATCH"; break;
			case EGL_BAD_PARAMETER:                 	error = "EGL_BAD_PARAMETER"; break;
			case EGL_BAD_NATIVE_PIXMAP:             	error = "EGL_BAD_NATIVE_PIXMAP"; break;
			case EGL_BAD_NATIVE_WINDOW:                	error = "EGL_BAD_NATIVE_WINDOW"; break;
			case EGL_CONTEXT_LOST:               		error = "EGL_CONTEXT_LOST"; break;
		}
		std::cout << error << " | " << file << " (" << line << ")" << std::endl;
	}
}

void glDebugContexOutput(GLenum source,
			 GLenum type,
			 unsigned int id,
			 GLenum severity,
			 GLsizei length,
			 const char *glmessage,
			 const void *user_param)
{
	std::cout << "gles debug message:" <<  glmessage << std::endl;
}